﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using Dataglot;

namespace IrishSettings.Commands
{
    public class SelectSchemaByName:GenericCommand
    {
        public SelectSchemaByName(DataFactory factory)
            : base(factory)
        {
            Construct();
        }

        private void Construct()
        {
            const string sql = @"
SELECT     * 
FROM         {$ns}_settings_schema
WHERE 
    name= @name
and
    application_id = @applicationId
";
            ComposeSql(sql);
            AddParameter("@name", DbType.String);
            AddParameter("@applicationId", DbType.Int64);
        }

        public SelectSchemaByName(DataFactory factory, DbConnection shared, DbTransaction transaction)
            : base(factory, shared, transaction)
        {
            Construct();
        }

        public DbDataReader Select(string name, long applicationId)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException("Missing name", "name");

            command.Parameters["@name"].Value = name;
            command.Parameters["@applicationId"].Value = applicationId;
            return ExecuteReader(CommandBehavior.SingleRow);
        }
    }
}
